package com.myprocessing.gui;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.myprocessing.controller.GuiController;

import processing.core.PApplet;

public class PGuiFrameApplet extends PApplet{

	protected static GuiController controller;
	protected ApplicationContext uiCtx;
	
	private static final String myClassName = getQualifiedClassName();

	static public void main(String _args[]) {
		PApplet.main(new String[] { myClassName });
	}
	
	public static String getQualifiedClassName() {
		return new Exception().getStackTrace()[1].getClassName();
	}

	protected static final Logger logger = Logger.getLogger(myClassName);
	
	public void setup() {
		uiCtx = new FileSystemXmlApplicationContext("gui.xml");
        controller = (GuiController)uiCtx.getBean("controller");

        GuiController.init(this, uiCtx);
        
		size(controller.getScreenManager().getSize().getX(), controller.getScreenManager().getSize().getY());
        
        smooth();
	}
	
	public void initP(){}

	public void keyPressed() {
		controller.onkeyPressed(key);
	}
	
	public void mouseReleased() {
		controller.onMousePress();
	}
	
	public void draw() {
		controller.draw();
	}

	public GuiController getController() {
		return controller;
	}

	public void setController(GuiController controller) {
		this.controller = controller;
	}

	public ApplicationContext getUiCtx() {
		return uiCtx;
	}

	public void setUiCtx(ApplicationContext uiCtx) {
		this.uiCtx = uiCtx;
	}
}
